# Part 1: Installing Git ## On Windows 1. Download Git: Go to the official Git website: [https://git-scm.com/download/win](https://git-scm.com/download/win) and download the latest version of Git for Windows. 2. Install Git: Run the downloaded installer. 3. Verify Installation: Open the Command Prompt (`cmd`) or Git Bash and type: ```bash git --version ``` --- ## On macOS 1. Using Homebrew: Running the following command in the Terminal: ```bash brew install git ``` 2. Alternative Installation via Xcode Command Line Tools: If you don't have Homebrew, you can install Git by installing Xcode Command Line Tools: ```bash xcode-select --install ``` 3. Verify Installation: Run the following command: ```bash git --version ``` --- ## Part 2: Initializing a Git Repository 1. Navigate to Your Project Directory: ```bash cd path/to/your/project ``` 2. Initialize the Git Repository: ```bash git init ``` - This command will create a `.git` directory in your project, which tracks all the changes made to the files. 3. Verify Repository Initialization: ```bash git status ``` - This will show the current status of your project, including any untracked files. --- ## Part 3: Basic Git Commands 1. Add All Files in your project directory to the staging area: ```bash git add . ``` 2. Commit Your Changes, After adding files to the staging area, commit the changes with a meaningful message: ```bash git commit -m "Initial commit for Lab 1" ``` 3. View Commit History: ```bash git log ``` --- ## Part 4: Pushing Changes to Remote(GitHub) 1. Create a New Repository on GitHub: Go to [GitHub](https://github.com) and create a new repository. 2. Link Your Local Repository to GitHub: ```bash git remote add origin https://github.com/yourusername/your-repository.git ``` 3. Push Changes to GitHub: - Push your local commits to the remote repository on GitHub: ```bash git push -u origin master ``` 4. Verify the Push: Go to your GitHub repository and verify that your files have been successfully pushed. --- ## Part 5: Using SSH: (Optional) SSH (Secure Shell) is a protocol that allows you to securely connect to a remote system. When working with Git, SSH is often used to authenticate with remote repositories without needing to enter your username and password each time. 1. Generate SSH Key: ```bash ssh-keygen -t rsa -b 4096 -C "your_email@example.com" ``` 2. Add SSH Key to SSH Agent: ```bash eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa ``` 3. Add SSH Key to GitHub: Copy the SSH key to your clipboard and add it to your GitHub account under Settings > SSH and GPG keys > Add SSH key. ```bash pbcopy < ~/.ssh/id_rsa.pub # macOS cat ~/.ssh/id_rsa.pub | clip # Windows ``` 4. Test SSH Connection: ```bash ssh -T git@github.com ```